/* eslint-disable no-shadow */
export function count({ search }) {
  return RSocket.rr({
    route: 'dmn.rules.count',
    args: { search },
  });
}

export function search({ search, pg }) {
  return RSocket.rs({
    route: 'dmn.rules',
    args: { search, pg },
  });
}

export function tags() {
  return RSocket.rr({
    route: 'dmn.rules.tags',
  });
}

export function get(id) {
  return RSocket.rr({
    route: `dmn.rules.${id}`,
  });
}

export function remove(id) {
  return RSocket.rr({
    route: `dmn.rules.${id}.delete`,
  });
}

/**
 * 上传规则文件
 * @param {Buffer} fileData ;
 * @returns 成功返回字节数，否则异常
 */
export function uploadRule(fileData) {
  return RSocket.rc({
    route: 'dmn.rules.upload',
    data: fileData,
    logLevel: 'trace',
  });
}

/**
 * 下载规则文件
 * @param {string} ruleId ;
 * @returns
 */
export function downloadRule(id) {
  return RSocket.rs({
    route: `dmn.rules.${id}.download`,
    binary: true,
  });
}

/**
 * 检测规则是否存在
 * @param {string} id  规则标识
 */
export function checkExists(id) {
  return RSocket.rr({
    route: `dmn.rules.${id}.exists`,
  });
}

